<?php 
	include_once ('class_tag.php');
	include_once('includes/class_pages.php');
	include_once ('components/danhmuc/class_danhmuc.php');
	
	
?>

<div class="art-post">
                                <div class="art-post-tl"></div>
                                <div class="art-post-tr"></div>
                                <div class="art-post-bl"></div>
                                <div class="art-post-br"></div>
                                <div class="art-post-tc"></div>
                                <div class="art-post-bc"></div>
                                <div class="art-post-cl"></div>
                                <div class="art-post-cr"></div>
                                <div class="art-post-cc"></div>
                                <div class="art-post-body">
                            <div >
                                            <div class="art-postmetadataheader">
                                                <h2 class="art-postheader">
                                                    <img src="images/postheadericon.png" width="32" height="32" alt="postheadericon" />
                                                    Tag '<?php echo $_GET['TenTag'] ?>'
                                                </h2>
                                            </div>
                                            <div class="art-postcontent"><br/>
                                                <!-- article-content -->

<?php
	$tag = new class_tag();
	$count = $tag->CountListSanPhamByTag($_GET['MaTag']);
	
	$pager = new Pager();
	$limit = 3;
		
	$start = $pager->findStart($limit);
	$pages = $pager->findPages($count,$limit);

	$ls = 'com=tag&fun=detail&MaTag='.$_GET['MaTag'].'&TenTag='.$_GET['TenTag'] ;
	$listpaging = '' ;
	if($count > $limit)
	{
		$listpaging = $pager->pageList($_GET['page'], $pages,$ls);
	}

	$tb = $tag->ListSanPhamByTag($_GET['MaTag'],$start,$limit);
	$str = '';
	if (count($tb) == 0)
	{
		echo '<br/><div align="center"><b>Không có sản phẩm.</b></div>';
	}
	foreach ($tb as $row)
	{
		$str = '<table align="center" width="710" border="0">
  <tr>
    <td width="130" rowspan="6"><img src="../images/sanpham/'.$row['HinhAnh'].'" width="120px" height="160px" /></td>
    <td align="left" colspan="2" style="font-weight:bold; font-size:16px">';
	
	if ($row['TenSanPham'] == NULL)
	{
		$row['TenSanPham'] = 'sản phẩm bị xóa';
	}
	
	$str .= '<a href="index.php?com=sanpham&fun=detail&MaSanPham='.$row['MaSo'].'">'.$row['TenSanPham'].'</a></td>
  </tr>
  <tr>
    <td width="290">Danh mục: '.$row['TenDanhMuc'].'</td>
	<td>Người bán: '.$row['Username'].'</td>
  </tr>
  <tr>
    <td>Giá bán: '.$row['GiaSanPham'].' VND</td>
	<td>Số lượng: '.$row['SoLuong'].' '.$row['TenDonViTinh'].' </td>
  </tr>
  <tr>
    <td>Nhà sản xuất: '.$row['NhaSanXuat'].'</td>
	<td>Điểm: '.$row['DiemDanhGia'].'</td>
  </tr>
  <tr>';
  
	$ThoiGian = $row['NgayDang'];
	$nam = substr($ThoiGian,0,4);
	$thang = substr($ThoiGian,5,2);
	$ngay = substr($ThoiGian,8,2);
	$gio = substr($ThoiGian,11,2);
	$phut = substr($ThoiGian,14,2);
	$giay = substr($ThoiGian,17,2);
	$ThoiGian = $gio.':'.$phut.':'.$giay.' '.$ngay.'/'.$thang.'/'.$nam;
  
    $str .= '<td>Ngày đăng: '.$ThoiGian.'</td>
	<td>Lượt xem: '.$row['PageView'].'</td>
  </tr>';
  
  if($row['HaveTag'] == 1)
  {
	  $dm = new class_danhmuc();
	  $str .= '<tr>
    				<td colspan="2">Tag:';
	  $tbTag = $dm->ListTagByMaSanPham($row['MaSo']);
	  foreach ($tbTag as $rowTag)
	  {
		  $str .= ' <a href="index.php?com=tag&fun=detail&MaTag='.$rowTag['MaSo'].'&TenTag='.$rowTag['TenTag'].'">'.$rowTag['TenTag'].'</a>';
	  }
	  $str .= '</td>
  				</tr>';
  }
  else
  {
	  $str .= '<tr>
    			<td colspan="2"></td>
  			</tr>';
  }
  
  
  $str .= '<tr>
    <td colspan="3">
    <hr align="center" style="border:thin dotted" color="#00CC00"  />
    </td>
 </tr>
</table>';
		echo $str;
	}
	echo '<div align="center">'.$listpaging.'</div>';
?>

<!-- /article-content -->
                                            </div>
                                            <div class="cleared"></div>
                            </div>
                            
                            		<div class="cleared"></div>
                                </div>
                            </div>